package ch0001;

import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.event.*;

public class MyFrame3_1 extends JFrame {

	JLabel label_name;
	JTextField text_name;
	JLabel labelpassword;
	JPasswordField password1;
	JButton button1;
	JButton button2;
//	JLabel label_sn;
//	JTextField text_sn;
//	JLabel label_major;
//	JTextField text_major;
//	JLabel label_class;
//	JTextField text_class;
//	JLabel label_en_score;
//	JTextField text_en_score;
//	JLabel label_math_score;
//	JTextField text_math_score;

	public MyFrame3_1() {
		setTitle("作业1");
		setSize(500, 300);
		label_name = new JLabel("姓名");
		text_name = new JTextField(10);
		labelpassword = new JLabel("密码");
		password1 = new JPasswordField(10);
//		label_sn = new JLabel("学号");
//		text_sn = new JTextField(10);
//		label_major = new JLabel("专业");
//		text_major = new JTextField(10);
//		label_class = new JLabel("班级");
//		text_class = new JTextField(10);
//		label_en_score = new JLabel("英语成绩");
//		text_en_score = new JTextField(10);
//		label_math_score = new JLabel("数学成绩");
//		text_math_score = new JTextField(10);
		button1 = new JButton("确定");
//		button2 = new JButton("取消");

		Container c1 = getContentPane();
		c1.setLayout(new FlowLayout());
		c1.add(label_name);
		c1.add(text_name);
		c1.add(labelpassword);
		c1.add(password1);
//		c1.add(label_sn);
//		c1.add(text_sn);
//		c1.add(label_major);
//		c1.add(text_major);
//		c1.add(label_class);
//		c1.add(text_class);
//		c1.add(label_en_score);
//		c1.add(text_en_score);
//		c1.add(label_math_score);
//		c1.add(text_math_score);
		c1.add(button1);
		button1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				System.out.println("OK！");
				if (text_name.getText().trim().equals("abc") && password1.getText().trim().equals("123")) {
					System.out.println("login now!");
					MyFrame2 myf2 = new MyFrame2();
					myf2.show();
					myf2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}

			}

		});
//		c1.add(button2);
		setVisible(true);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyFrame3_1 stu2 = new MyFrame3_1();
		stu2.show();
		stu2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}
